import type Handsontable from 'handsontable'

export default function useValidate(hot: Handsontable) {
  return async function validate() {
    return new Promise<boolean | Error>((resolve, reject) => {
      hot.validateCells((valid) => {
        if (valid) {
          resolve(true)
        }
        else {
          ElMessage.warning('存在填写格式错误')
          reject(new Error('存在填写格式错误'))
        }
      })
    })
  }
}
